home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP11.ZIP
/
CHAP11
/
COSCHMOO
/
COSCHMOO.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-15
|
14KB
|
615 lines
/*
* COSCHMOO.CPP
* Component Schmoo Chapter 11
*
* WinMain and CSchmooFrame implementations.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#define INITGUIDS
#include "coschmoo.h"
/*
* WinMain
*
* Purpose:
* Main entry point of application. Should register the app class
* if a previous instance has not done so and do any other one-time
* initializations.
*/
int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pszCmdLine, int nCmdShow)
{
LPCSchmooFrame pFR;
FRAMEINIT fi;
WPARAM wRet;
#ifndef WIN32
SetMessageQueue(96);
#endif
//Attempt to allocate and initialize the application
pFR=new CSchmooFrame(hInst, hPrev, pszCmdLine, nCmdShow);
fi.idsMin=IDS_FRAMEMIN;
fi.idsMax=IDS_FRAMEMAX;
fi.idsStatMin=IDS_STATMESSAGEMIN;
fi.idsStatMax=IDS_STATMESSAGEMAX;
fi.idStatMenuMin=ID_MENUFILE;
fi.idStatMenuMax=ID_MENUHELP;
fi.iPosWindowMenu=WINDOW_MENU;
fi.cMenus=CMENUS;
//If we can initialize pFR, start chugging messages
if (pFR->FInit(&fi))
wRet=pFR->MessageLoop();
delete pFR;
return wRet;
}
/*
* CSchmooFrame::CSchmooFrame
* CSchmooFrame::~CSchmooFrame
*
* Constructor Parameters:
* hInst HINSTANCE from WinMain
* hInstPrev HINSTANCE from WinMain
* pszCmdLine LPSTR from WinMain
* nCmdShow int from WInMain
*/
CSchmooFrame::CSchmooFrame(HINSTANCE hInst, HINSTANCE hInstPrev
, LPSTR pszCmdLine, int nCmdShow)
: CFrame(hInst, hInstPrev, pszCmdLine, nCmdShow)
{
UINT i;
for (i=0; i<5; i++)
m_hBmpLines[i]=NULL;
m_fInitialized=FALSE;
return;
}
CSchmooFrame::~CSchmooFrame(void)
{
UINT i;
for (i=0; i<5; i++)
{
if (NULL!=m_hBmpLines[i])
DeleteObject(m_hBmpLines[i]);
}
//CHAPTER8MOD
OleFlushClipboard();
//End CHAPTER8MOD
if (m_fInitialized)
CoUninitialize();
return;
}
/*
* CSchmooFrame::FInit
*
* Purpose:
* Call CoInitialize then calling down into the base class
* initialization.
*
* Parameters:
* pFI LPFRAMEINIT containing initialization parameters.
*
* Return Value:
* BOOL TRUE if initialization succeeded, FALSE otherwise.
*/
BOOL CSchmooFrame::FInit(LPFRAMEINIT pFI)
{
DWORD dwVer;
dwVer=OleBuildVersion();
if (rmm!=HIWORD(dwVer))
return FALSE;
if (FAILED(OleInitialize(NULL)))
return FALSE;
m_fInitialized=TRUE;
return CFrame::FInit(pFI);
}
/*
* CSchmooFrame::CreateCClient
*
* Purpose:
* Constructs a new client specific to the application.
*
* Parameters:
* None
*
* Return Value:
* LPCClient Pointer to the new client object.
*/
LPCClient CSchmooFrame::CreateCClient(void)
{
return (LPCClient)(new CSchmooClient(m_hInst));
}
/*
* CSchmooFrame::FPreShowInit
*
* Purpose:
* Called from FInit before intially showing the window. We do whatever
* else we want here, modifying nCmdShow as necessary which affects
* ShowWindow in FInit.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if this initialization succeeded, FALSE otherwise.
*/
BOOL CSchmooFrame::FPreShowInit(void)
{
CreateLineMenu();
CheckLineSelection(IDM_LINESOLID);
m_pGB->Check(IDM_LINESOLID, TRUE);
return TRUE;
}
/*
* CSchmooFrame::CreateLineMenu
*
* Purpose:
* Initializes the bitmaps used to create the Line menu and replaces
* the text items defined in the application resources with these
* bitmaps. Note that the contents of m_hBmpLines must be cleaned
* up when the application terminates.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CSchmooFrame::CreateLineMenu(void)
{
HMENU hMenu;
HDC hDC, hMemDC;
HPEN hPen;
HGDIOBJ hObj;
TEXTMETRIC tm;
UINT i, cx, cy;
hMenu=GetSubMenu(GetMenu(m_hWnd), 3); //Line menu.
hDC=GetDC(m_hWnd);
//Create each line in a menu item 8 chars wide, one char high.
GetTextMetrics(hDC, &tm);
cx=tm.tmAveCharWidth*8;
cy=tm.tmHeight;
//Create a memory DC in which to draw lines, and bitmaps for each line.
hMemDC=CreateCompatibleDC(hDC);
ReleaseDC(m_hWnd, hDC);
for (i=0; i<5; i++)
{
m_hBmpLines[i]=CreateCompatibleBitmap(hMemDC, cx, cy);
SelectObject(hMemDC, m_hBmpLines[i]);
PatBlt(hMemDC, 0, 0, cx, cy, WHITENESS);
hPen=CreatePen(i, 1, 0L); //i==line style like PS_SOLID
hObj=SelectObject(hMemDC, hPen);
MoveTo(hMemDC, 0, cy/2);
LineTo(hMemDC, cx, cy/2);
ModifyMenu(hMenu, IDM_LINEMIN+i, MF_BYCOMMAND | MF_BITMAP
, IDM_LINEMIN+i, (LPCSTR)MAKELONG(m_hBmpLines[i], 0));
SelectObject(hMemDC, hObj);
DeleteObject(hPen);
}
CheckMenuItem(hMenu, IDM_LINESOLID, MF_CHECKED);
DeleteDC(hMemDC);
return;
}
/*
* CSchmooFrame::CreateGizmos
*
* Purpose:
* Procedure to create all the necessary gizmobar buttons.
*
* Parameters:
* None
*
* Return Value:
* UINT Number of gizmos added to the bar.
*/
UINT CSchmooFrame::CreateGizmos(void)
{
UINT iLast;
UINT uState=GIZMO_NORMAL;
UINT utCmd =GIZMOTYPE_BUTTONCOMMAND;
UINT utEx =GIZMOTYPE_BUTTONATTRIBUTEEX;
//Insert the standard ones.
iLast=CFrame::CreateGizmos();
//Insert File Import in the 5th position and account for it in iLast.
m_pGB->Add(utCmd, 4, IDM_FILEIMPORT, m_dxB, m_dyB, NULL, m_hBmp, 2, uState);
iLast++;
//Separator
m_pGB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB, NULL, NULL, 0, uState);
//For the Background bitmap, preserve our use of black (part of the image)
m_pGB->Add(utCmd, iLast++, IDM_COLORBACKGROUND, m_dxB, m_dyB, NULL, m_hBmp, 3
, GIZMO_NORMAL | PRESERVE_BLACK);
m_pGB->Add(utCmd, iLast++, IDM_COLORLINE, m_dxB, m_dyB, NULL, m_hBmp, 4, uState);
//Separator
m_pGB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB, NULL, NULL, 0, uState);
//Line styles.
m_pGB->Add(utEx, iLast++, IDM_LINESOLID, m_dxB, m_dyB, NULL, m_hBmp, 5, uState);
m_pGB->Add(utEx, iLast++, IDM_LINEDASH, m_dxB, m_dyB, NULL, m_hBmp, 6, uState);
m_pGB->Add(utEx, iLast++, IDM_LINEDOT, m_dxB, m_dyB, NULL, m_hBmp, 7, uState);
m_pGB->Add(utEx, iLast++, IDM_LINEDASHDOT, m_dxB, m_dyB, NULL, m_hBmp, 8, uState);
m_pGB->Add(utEx, iLast++, IDM_LINEDASHDOTDOT, m_dxB, m_dyB, NULL, m_hBmp, 9, uState);
return iLast;
}
/*
* CSchmooFrame::OnCommand
*
* Purpose:
* WM_COMMAND handler for the Schmoo frame window that just processes
* the line menu and the color menu leaving the CFrame to do everything
* else.
*
* Parameters:
* hWnd HWND of the frame window.
* wParam WPARAM of the message.
* lParam LPARAM of the message.
*
* Return Value:
* LRESULT Return value for the message.
*/
LRESULT CSchmooFrame::OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
LPCSchmooDoc pDoc;
char szFile[CCHPATHMAX];
BOOL fOK;
UINT i, uTemp;
COLORREF rgColors[16];
CHOOSECOLOR cc;
COMMANDPARAMS(wID, wCode, hWndMsg);
/*
* Don't bother with anything during first initialization,
* skipping many GizmoBar notifications.
*/
if (m_fInit)
return 0L;
pDoc=(LPCSchmooDoc)m_pCL->Ac